package libs

import (
	"fmt"
	"os"
	"sync"
	"time"
)

var (
	recentFiles = make(map[string]time.Time)
	fileMutex   sync.Mutex
	lastRename  struct {
		oldPath string
		time    time.Time
	}
	renameMutex sync.Mutex
)

func FileExists(filename string) bool {
	_, err := os.Stat(filename)
	return !os.IsNotExist(err)
}

func contains(slice []string, item string) bool {
	for _, s := range slice {
		if s == item {
			return true
		}
	}
	return false
}

func DebugPrint(format string, args ...interface{}) {
	if Config.Debug {
		PrintAndFlush(fmt.Sprintf(format, args...))
	}
}

// PrintAndFlush 输出字符串并立即刷新缓冲区
func PrintAndFlush(s string) {
	os.Stdout.WriteString(s)
	os.Stdout.Sync()
}
